package com.ht.base.system.biz.convert;

import com.ht.base.system.common.pojo.bo.SysRoleMenuBO;
import com.ht.base.system.dao.domain.SysRoleMenuDO;
import org.apache.commons.collections.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 类SysRoleMenuBeanUtil.java的实现描述：角色和菜单关联表工具类
 * 
 * @Author hdx
 * @Date 2023年04月28日
 */
public class SysRoleMenuBeanUtil {

    private SysRoleMenuBeanUtil(){
    }

    public static SysRoleMenuDO sysRoleMenuBOToDO(SysRoleMenuBO srcObj) {
        if (srcObj == null) {
            return null;
        }
        SysRoleMenuDO targetObj = new SysRoleMenuDO();
        targetObj.setId(srcObj.getSysRoleMenuId());//主键
        targetObj.setSysRoleId(srcObj.getSysRoleId());//角色ID
        targetObj.setSysMenuId(srcObj.getSysMenuId());//菜单ID
        targetObj.setMenuName(srcObj.getMenuName());
        targetObj.setPerms(srcObj.getPerm());
        targetObj.setUpdateTime(srcObj.getUpdateTime());//updateTime
        return targetObj;
    }

    public static SysRoleMenuBO sysRoleMenuDOToBO(SysRoleMenuDO srcObj) {
        if (srcObj == null) {
            return null;
        }
        SysRoleMenuBO targetObj = new SysRoleMenuBO();
        targetObj.setSysRoleMenuId(srcObj.getId());//主键
        targetObj.setSysRoleId(srcObj.getSysRoleId());//角色ID
        targetObj.setSysMenuId(srcObj.getSysMenuId());//菜单ID
        targetObj.setMenuName(srcObj.getMenuName());
        targetObj.setPerm(srcObj.getPerms());
        targetObj.setUpdateTime(srcObj.getUpdateTime());//updateTime
        return targetObj;
    }

    public static List<SysRoleMenuBO> doList2BOList(List<SysRoleMenuDO> doList) {
        List<SysRoleMenuBO> boList = new ArrayList<>();
        if (CollectionUtils.isEmpty(doList)) return boList;

        doList.stream().forEach(d -> boList.add(SysRoleMenuBeanUtil.sysRoleMenuDOToBO(d)));
        return boList;
    }

    public static List<SysRoleMenuDO> boList2DOList(List<SysRoleMenuBO> boList) {
        List<SysRoleMenuDO> doList = new ArrayList<>();
        if (CollectionUtils.isEmpty(boList)) return doList;

        boList.stream().forEach(b -> doList.add(SysRoleMenuBeanUtil.sysRoleMenuBOToDO(b)));
        return doList;
    }
}